<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="../../util/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>添加部门</title>
</head>
<body>
<div id="editGroupForm">
        <div class="form-Container">
            <form action="${pageContext.request.contextPath}/group/editGroup.do"  id="dataForm" class="grayForm" method="post">
                <input type="hidden" name="id" value="${param.id }"/>
                <input type="hidden" name="uuid" id="uuid" value=""/>
                <table>
                    <tr>
                        <td ><label for="groupName">角色名字:</label></td>
                        <td style="line-height:20px;"><input type="text" id="groupName" required name="groupName"  /></td>
                    </tr>
                    <tr>   
                        <td><label for="groupDesc">备注:</label></td>
                        <td colspan="3" style="line-height:20px;"><input type="text" name="groupDesc" id="groupDesc"/></td>
                    </tr>
                    <tr>
                        <td colspan="4" style="text-align: center;">
                            <input type="button" value="提交数据" name="submitData" />
                        </td>
                    </tr>
                </table>
                <div id="confirmMsg"></div>
            </form>
        </div>
</div>
        <script type="text/javascript">
        $(document).ready(function () {
        	var id = new Number($("#editGroupForm  input[name='id']").val());
        	var rules = {
        		groupName:{
        			remote:"<%=path %>/group/checkGroupName.do"
        		}
        	}
        	var messages = {}
        	messages = {
        			groupName:{
        				required:"请输入角色名字",
        				remote:'你输入的角色名已存在！'
        			}
            };
        	
        	var validateForm = $("#editGroupForm #dataForm").validate({
                debug:true,
                rules:rules,
                messages:messages
            });
        	
            //提交数据到服务器
            $("#editGroupForm input[name='submitData']").click(function () {
            	//提交表单进行验证
            	$("#editGroupForm #dataForm").submit();
                var validateFlag = validateForm.form();
                var actionUrl = $("#editGroupForm #dataForm").attr("action");
            	var formData  = $("#editGroupForm #dataForm").form2Json();
            	if(validateFlag){
            		$.post(actionUrl,{formData:formData},function(data){
            			if(data.code=="00"){
          				  $.messager.confirm('操作确认',data.msg+',请确认是否继续操作？', function(flag){
          					  if(flag){
          						  $("#editDataFormArea").window("close");
          						  $('#groupListPage .groupTree').tree('reload');
          					  }
          				  });
          			    }else{
          				   $.messager.alert('操作提示',data.msg,'error');
          			    }
            		},"json");
            	}
            });
            
        	if(id>0){
        		//加载表单数据
            	loadFormData(id+"");
        		//$("#confirmMsg").html("<font color=red><b>注：修改用户信息时，密码输入框留空则代表不修改密码！</b></font>");
        	}
        });
        
        //通过表单加载数据
        function loadFormData(id){
        	$.post(getBasePath()+"/GroupController/getJsonDetail.do",{id:id},function(jsonData){
        		for(var jsonKey in jsonData.data){
        			//alert(jsonKey);
        			try{
        				var thisDom = document.getElementById(jsonKey);
            			var domHtml = thisDom.outerHTML;
            			if(domHtml.indexOf("input")>-1){
                			$("input[name='"+jsonKey+"']").val(jsonData.data[jsonKey]);
                		}else if(domHtml.indexOf("select")>-1){
                			$("select[name='"+jsonKey+"']").find("option[value='"+jsonData.data[jsonKey]+"']").attr("selected",true);
                		}else{
                			$("#"+jsonKey+"").val(jsonData.data[jsonKey]);
                		}
        			}catch (e) {
        				
					}
        		}
  		    },"json");
        }
    </script>
</body>
</html>